package testingApp;

import java.util.List;

import org.apache.commons.dbcp.BasicDataSource;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.CannotGetJdbcConnectionException;

import clientClasses.Category;
import clientClasses.CategoryDAO;
import clientClasses.Menu;

public class App {
	public static void main(String[] args) {
		Menu menu = Menu.getInstance();

		for (int i = 0; i < 5; i++) {
			Category c = new Category();
			c.setId(i);
			c.setName("Name" + i);
			menu.addCategory(c);
		}

		System.out.println(menu.toJson().toString());

		ApplicationContext context = new ClassPathXmlApplicationContext(
				"beans/beans.xml");

		CategoryDAO categoryDao = (CategoryDAO) context.getBean("categoryDao");

		try {

			List<Category> categories = categoryDao.getCategories();

			for (Category category : categories) {
				System.out.println(category);
			}

		} catch (CannotGetJdbcConnectionException ex) {
			System.out.println("Unable to connect to database.");
		} catch (DataAccessException ex) {
			System.out.println(ex.getMessage());
			System.out.println(ex.getClass());
		}

		((ClassPathXmlApplicationContext) context).close();
	}

}
